<template>
	<view class="content ">
		<view class="list" v-for="(item,index) in list" @click="xzAaa(item)">
			<view class="l-l">
				<view class="home" v-if="item.defaultType==1">
					<u-icon name="home-fill" color="#fff" size="30" ></u-icon>
				</view>
				<view class="home1" v-if="item.defaultType==0">
					<u-icon name="home-fill" color="#fff" size="30" ></u-icon>
				</view>
			</view>
			<view class="wrapper">
				<view class="address-box">
					<text class="address">{{item.provinceName}}{{item.cityName}}{{item.areaName}}{{item.streetName}}{{item.detail}}</text>
				</view>
				<view class="u-box">
					<view class="namebox">
						<text class="name">{{item.userName}}</text>
						<text class="mobile">{{item.userPhone}}</text>
					</view>
					<view class="box-r">
						<view @click.stop="del(item.addressId)">
							<u-icon name="trash" color="#666666" size="40" ></u-icon>
						</view>
						<view @click.stop="setadd(item)">
							<u-icon name="edit-pen" color="#666666" size="40" ></u-icon>
						</view>
					</view>
				</view>

			</view>
		</view>
		<button class="add-btn" @click="toadd">新增地址</button>
	</view>
</template>

<script>
	import {
addlist,deladdress
	} from '../../api/product.js'
	export default {
		data() {
			return {
				list: [],
				num: 1,
				type:null
			}
		},
		onLoad(e) {
			if(e.type){
				this.type=e.type
			}
			console.log(this.type)
		},
		onShow() {
			this.num=1
			this.list=[]
			this.getlist()
		},
		onReachBottom() {
			this.getlist()
		},
		methods: {
			async getlist() {
				let res = await this.get(addlist)
				this.num++
				res.data.forEach(item => {
					this.list.push(item)
				})
			},
			// 选择地址
			xzAaa(data){
				if(this.type!=null){
					console.log("发布成功")
					uni.$emit('setAddress',data)
					uni.navigateBack({
						delta:1
					})
				}
			},
			// 新建
			toadd() {
				uni.navigateTo({
					url: "/pages/address/addaddress"
				})
			},
			// 修改
			setadd(obj) {
				uni.navigateTo({
					url: "/pages/address/addaddress?obj=" + JSON.stringify(obj)
				})
			},
			// 删除
			async del(id) {
				this.showMd("确认删除",()=>{
					this.get(deladdress, {
						addressId: id
					}).then(res=>{
						this.msg('删除成功','none')
						this.list = []
						this.num = 1
						this.getlist()
					})
				})
				
			}
		}
	}
</script>

<style>
	.home{
		background-color:#F0812D ;
		border-radius: 50%;
		width: 40rpx;
		height: 40rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative;
		top: -40rpx;
	}
	.home1{
		background-color:#999;
		border-radius: 50%;
		width: 40rpx;
		height: 40rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		position: relative;
		top: -40rpx;
	}
	.l-l{
		width:60rpx;
		display: flex;
		justify-content: center;
		height: 100%;
	}
	.list {
		display: flex;
		background-color: #FFFFFF;
		margin-bottom: 10rpx;
		align-items: center;
		padding: 30rpx 0;
	}
	.box-r {
		width: 120rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.content {
		padding-bottom: 100rpx;
	}

	.add-btn {
		background-color: #F0812D;
		color: #FFFFFF;
		width: 690rpx;
		margin-left: 30rpx;
		position: fixed;
		bottom: 30rpx;
	}

	.name {
		margin-right: 20rpx;
	}

	.namebox {
		font-size: 28rpx;
		color: #666666;
	}

	.u-box {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.address {
		font-size: 28rpx;
		color: #666666;
		height: 70rpx;
		line-height: 35rpx;
	}

	.tag {
		width: 70rpx;
		margin-right: 10rpx;
		border: 1px #F0812D solid;
		color: #666666;
		font-size: 24rpx;
		color: #F0812D;
		text-align: center;
		line-height: 40rpx;
		padding: 0;
	}

	.address-box {
		display: flex;
		align-items: center;
	}

	.wrapper {
		width: 660rpx;
	}

	page {
		background-color: #F6F6F6;
	}
</style>
